﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PilotProject;

namespace PilotMVC
{ 
    public class AddressController : Controller
    {
        private PilotEntities1 db = new PilotEntities1();

   

       [HttpPost]
        public ActionResult Suburbs(string stateId)
        {
            var suburbs = db.Suburbs.Where(p => p.State.Id.Equals(stateId)).OrderBy(p => p.Locality).ToList();
            var result =  Json(suburbs.Select(s => new { s.Id, s.Locality }));
            return result;
        }


       [HttpPost]
       public ActionResult States()
       {
           var states = db.States.OrderBy(s => s.Description).ToList();
           var result = Json(states.Select(s => new { s.Id, s.Description}));
           return result;
       }


        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}